﻿var usermanage = {
    init: function () {
        var _html = [];

        //_html.push('<div data-options="region:\'center\'"  title="相关信息">');

        _html.push('<div id="tt" class="easyui-tabs" data-options="fit:\'true\'" >');
        _html.push('<div title=' + lang.basic_information + ' id="t1" data-options="fit:\'true\'" >');
        _html.push('<div id="userinfo_1" style="padding:10px;" class="tablelist">');
        _html.push('</div></div>');
        _html.push('<div title=' + lang.group + '  id="t2" data-options="fit:\'true\'">');

        _html.push('<div style="font-size:14px; font-weight:bold; margin-left:10px; margin-top:10px;">' + lang.user_group + '</div>');
        _html.push('<hr style="color:#D4D4D4">');
        _html.push('<div id="userinfo_2" style="padding:10px;"><div id="rolegd" ></div></div>');
        _html.push('<div style="font-size:14px; font-weight:bold; margin-left:10px; margin-top:10px;">' + lang.file_operation_pemission + '</div>');
        _html.push('<hr>');

        _html.push('<div id="userinfo_3" style="font-size:13px;"><ul style="list-style:none;font-size:13px;"><li>' + lang.Online_Browse_file + '：<span id="file_see_secr"></span></li><li>' + lang.Download_PDF_format_file + '：<span id="file_down_secr"></span></li><li>' + lang.Download_the_original_file + '：<span id="file_source_secr"></span></li></ul></div>');
        _html.push('</div>');
        //        _html.push('<div title="权限"  id="t3">');
        //        
        //        _html.push('</div>');
        _html.push('<div title=' + lang.zone + '  id="t4">');
        _html.push('<div id="userinfo_4" style="padding:10px;"><div id="spacenamegd"></div></div>');
        _html.push('</div>');

        _html.push('</div>');
        // _html.push('</div>');

        $('body').html(_html.join(''));
        $('body').addClass('easyui-layout');
        $.parser.parse();
        $('#tt').tabs({
            border: false,
            onSelect: function (id) {
                if (id == "t2") { rolelist(); rightlist(); }
                else if (id == "t3") { rightlist(); }
                else if (id == "t4") { bindUserMenu(); }
            }
        });
        bindUserInfo();

    }
};

//#region 用户信息
var _userinfodata;
function bindUserInfo() {
    var _html = [];
    _html.push('<table  style="width:100%;">');
    _html.push('<tr><td  class="tb_title">' + lang.name + '</td><td><span id="USER_NAME"></span><span id="edit" style="padding:2px 10px;cursor:pointer;border:1px solid #ccc;background:#f0f0f0;float:right;">' + lang.modify + '</span></td></tr>');
    _html.push('<tr><td class="tb_title">' + lang.Account + '</td><td><span id="USER_ACCOUNT"></span></td></tr>');
//    _html.push('<tr id="tr_password"><td class="tb_title">' + lang.Login_password + '</td><td><span id="USER_PWD">******</span><span id="edit_psw" style="padding:2px 10px;cursor:pointer;border:1px solid #ccc;background:#f0f0f0;float:right;">' + lang.reset + '</span></td></tr>');
//    _html.push('<tr id="renewpwd" style="display:none;"><td class="tb_title">' + lang.confirm_password + '</td><td><input type="password" id="REUSER_PWD1" style="width:120px;"></input><span style="color:red;">*</span></td></tr>');
    _html.push('<tr id=tr_number><td style="width:80px;" class="tb_title">' + lang.number + '</td><td><span id="USER_CODE"></span></td></tr>');
    _html.push('<tr id="tr_user_sex"><td class="tb_title">' + lang.user_sex + '</td><td><span id="USER_SEX"></span></td></tr>');
    _html.push('<tr id="tr_language"><td class="tb_title">' + lang.language + '</td><td><span id="lange_type"></span></td></tr>');
    //_html.push('<tr><td class="tb_title">创建时间</td><td><span id="CREATEDATE"></span></td></tr>');
    _html.push('<tr><td class="tb_title">' + lang.email + '</td><td><span id="EMAIL"></span></td></tr>');
    _html.push('<tr><td class="tb_title">' + lang.contact_way + '</td><td><span id="telphone"></span></td></tr>');
    _html.push('<tr><td class="tb_title">' + lang.space_state + '</td><td><span id="spacestatue"></span></td></tr>');
    _html.push('<tr><td class="tb_title">' + lang.size_of_the_zone_ + '</td><td>' + lang.used_size_of_zone + ' <span id="SPACE_CURE_USE"></span>&nbsp;GB；' + lang.Surplus + ' <span id="PACE_SURPLUS_SIZE"></span>&nbsp;GB</td></tr>');
    _html.push('<tr><td class="tb_title">' + lang.department + '</td><td><span id="ORGANIZATION_NAME"></span></td></tr>');
    _html.push('<tr><td class="tb_title">' + lang.score + '</td><td><span id="INTEGRAL"></span></td></tr>');
    _html.push('<tr><td class="tb_title"  style="height:80px;">' + lang.description + '</td><td><span id="USER_REMARK"></span></td></tr>');
    _html.push('<tr id="saveuserinfo" style="display:none;"><td colspan="2" align="center"><span id="saveinfo" style="padding:4px 10px;cursor:pointer;border:1px solid #ccc;background:#f0f0f0;">' + lang.save + '</span><span style="padding:4px 10px;"> </span><span id="cancleinfo" style="padding:4px 10px;cursor:pointer;border:1px solid #ccc;background:#f0f0f0;">' + lang.cancel + '</span></td></tr>');
    _html.push('</table>');
    _html.push('<div style="height:1px;clear:both;"></div>');
    $('#userinfo_1').html(_html.join(''));

    $.ajaxHandler({
        url: App_Config.TadongUrl + "/AjaxMappingHandler.aspx",
        urlType: "GetCurrentUser",
        success: function (data) {
            if (data) {
                _userinfodata = data;
                $('#USER_CODE').html(data.USER_CODE);
                $('#USER_NAME').html(data.USER_NAME);
                $('#USER_ACCOUNT').html(data.USER_ACCOUNT);
                var sexstr = '';
                if (data.USER_SEX == 1) { sexstr = lang.male; } else { sexstr = lang.female; }
                $('#USER_SEX').html(sexstr);
                $('#EMAIL').html(data.EMAIL);
                $('#CREATEDATE').html(data.CREATEDATE);
                $('#telphone').html(data.TELPHONE);
                var langstr = '';
                if (data.USER_LANG == 1) { langstr = lang.chinese } else if (data.USER_LANG == 0) { langstr = 'English'; }
                $('#lange_type').html(langstr);
                var spacestatusstr = '';
                if (data.SPACE_STATUS == 0) { spacestatusstr = lang.close; } else { spacestatusstr = lang.open; }
                $('#spacestatue').html(spacestatusstr);


                $('#SPACE_CURE_USE').html(data.SPACE_CURE_USE);
                $('#PACE_SURPLUS_SIZE').html(data.PACE_SURPLUS_SIZE);

//                $('#USER_PWD').html('******');

                //所在部门
                $('#ORGANIZATION_NAME').html(data.ORGANIZATION_NAME);
                //积分
                $('#INTEGRAL').html(data.INTEGRAL);

                $('#USER_REMARK').html(data.USER_REMARK);
                $('#edit').bind('click', function () {
                    //                    $('#renewpwd,#saveuserinfo').show();
                    //                    $('#USER_PWD').html('<input type="password" id="REUSER_PWD0" style="width:120px;"></input><span style="color:red;">*</span>');
                    $('#saveuserinfo').show();
//                    $('#edit_psw').hide();
//                    $('#tr_password').hide();
                    $('#EMAIL').html('<input type="text" id="EMAIL0" style="width:120px;"></input>');
                    $('#EMAIL0').val(_userinfodata.EMAIL);
                    $('#telphone').html('<input type="text" id="telphone0" style="width:120px;"></input>');
                    $('#telphone0').val(_userinfodata.TELPHONE);

                    $('#USER_SEX').html('<input type="radio" name="sex" value="1">' + lang.male + '<input type="radio" name="sex" value="0">' + lang.female);
                    $('input[name="sex"][value="' + _userinfodata.USER_SEX + '"]').attr("checked", true);
                    $('#lange_type').html('<input type="radio" name="langetype" value="1">' + lang.chinese + ' <input type="radio" name="langetype" value="0">English');
                    $('input[name="langetype"][value="' + _userinfodata.USER_LANG + '"]').attr("checked", true);

                    $('#USER_REMARK').html('<textarea rows="5"  id="user_remark0" style="width:95%;"></textarea>');
                    $('#user_remark0').val(_userinfodata.USER_REMARK);
                    $('#saveinfo').bind('click', function () { saveinfo(); });
                    $('#cancleinfo').bind('click', function () { location.reload(); });
                });
            }
        }
    });

//    //修改密码
//    $('#edit_psw').bind('click', function () {
//        psw_biao = 1;
//        //window.open("webhtml/modifyPsw.htm", "height=200,width=220,scrollbars=yes,status =yes,alwaysRaised=yes");
//        $('#edit_psw').hide();
//        $('#renewpwd').show();
//        $('#edit').hide();
//        $('#saveuserinfo').show();
//        $('#tr_number').hide();

//        $('#USER_PWD').html('<input type="password" id="REUSER_PWD0" style="width:120px;"></input><span style="color:red;">*</span>');
//        $('#saveinfo').bind('click', function () { saveinfo(); });
//        $('#cancleinfo').bind('click', function () { location.reload(); });
//    });


}


function saveinfo() {
//    if (psw_biao == 1) {
//        if ($('#REUSER_PWD0').val() == '') { alert(lang.The_login_password_cannot_be_empty); return; }
//        else if ($('#REUSER_PWD1').val() == '') { alert(lang.The_confirm_password_cannot_be_empty); return; }
//        else if ($('#REUSER_PWD0').val() != $('#REUSER_PWD1').val()) { alert(lang.The_two_password_do_not_match_please_input_again); return; }

//        $.ajaxHandler({
//            url: App_Config.TadongUrl + "/AjaxMappingHandler.aspx",
//            urlType: "EditStaffUserInfo",
//            model: function () {
//                var obj = {};
//                obj.USER_PWD = hex_md5($('#REUSER_PWD0').val());
//                //                obj.USER_SEX = $("input[name='sex']:checked").val();
//                obj.EMAIL = $('#EMAIL0').val();
//                obj.USER_REMARK = $('#user_remark0').val();
//                obj.TELPHONE = $('#telphone0').val();
//                //                obj.USER_LANG = $("input[name='langetype']:checked").val();
//                return $.toJSON(obj);
//            },
//            success: function (data) {
//                alert(lang.Password_updated_successfully);
//                $('#edit').show();
//                location.reload();
//            }
//        });
//    }
//    else {
        $.ajaxHandler({
            url: App_Config.TadongUrl + "/AjaxMappingHandler.aspx",
            urlType: "EditStaffUserInfo",
            model: function () {
                var obj = {};
                obj.USER_SEX = $("input[name='sex']:checked").val();
                obj.EMAIL = $('#EMAIL0').val();
                obj.USER_REMARK = $('#user_remark0').val();
                obj.TELPHONE = $('#telphone0').val();
                obj.USER_LANG = $("input[name='langetype']:checked").val();
                return $.toJSON(obj);
            },
            success: function (data) {
                alert(lang.Personal_data_updated_successfully);
                location.reload();
            }
        });
//    }

}
//#endregion

//#region 角色列表
function rolelist() {
    $.ajaxHandler({
        url: App_Config.TadongUrl + "/AjaxMappingHandler.aspx",
        urlType: "QueryCurrentUserRole",
        success: function (data) {
            $('#rolegd').datagrid({
                data: data, rownumbers: false,
                columns: [[
                //  { field: 'ROLES_ID', title: '角色ID', width: 140 },
                            {field: 'ROLES_NAME', title: lang.group, width: 563 }
                //{ field: 'ROLES_REMARK', title: '备注', width: 280, align: 'left' }
                            ]]
            });

        }
    });

}

//#endregion 

//#region 文件权限
var rightarrobj = { key_10: lang.open, key_20: lang.Secret, key_30: lang.Confidential, key_40: lang.Top_secret };
function rightlist() {
    $.ajaxHandler({
        url: App_Config.TadongUrl + "/AjaxMappingHandler.aspx",
        urlType: "GetUserMaxFileRole",
        success: function (data) {
            if (data) {
                $('#file_see_secr').text(rightarrobj['key_' + data.SEE_SECR]);
                $('#file_down_secr').text(rightarrobj['key_' + data.DOWN_PDF_SECR]);
                $('#file_source_secr').text(rightarrobj['key_' + data.DOWN_SOURCE_SECR]);
            }
        }
    });

}
//#endregion

//#region 有用权限
function bindUserMenu() {
    $.ajaxHandler({
        url: App_Config.TadongUrl + "/AjaxMappingHandler.aspx",
        urlType: "GetSpaceListByUserId",
        success: function (data) {
            $('#spacenamegd').datagrid({
                data: data, rownumbers: true,
                columns: [[
                //                  { field: 'SpaceId', title: '空间ID', width: 60 },
                {field: 'SpaceName', title: lang.zone_name, width: 375 },
                { field: 'IsAdmin', title: lang.administrator, width: 80, formatter: function (v, row, index) { if (row.IsAdmin) { return lang.yes; } else { return lang.no; } } },
                { field: 'IsOpen', title: lang.Whether_open, width: 80, formatter: function (v, row, index) { if (row.IsOpen) { return lang.yes; } else { return lang.no; } } }
                ]]
            });
        }
    });
}
//#endregion 